<template>
  <div class="container">
    <table>
      <thead>
      <tr id="table_header">
        <th>课程编号</th>
        <th>课程名称</th>
        <th>课程属性</th>
        <th>学分</th>
        <th>成绩</th>
      </tr>
      </thead>
      <tbody>
      <tr  v-if="!grades || grades.length===0">
        <td colspan="5">
          <div>
            该学期无成绩
          </div>
        </td>
      </tr>
      <tr v-for="course in grades" :key="course.courseNo">
        <td :data-label="'课程编号'">{{ course.courseNo }}</td>
        <td :data-label="'课程名称'">{{ course.courseName }}</td>
        <td :data-label="'课程属性'">{{ course.properties }}</td>
        <td :data-label="'学分'">{{ course.credit }}</td>
        <td :data-label="'成绩'">{{ course.score }}</td>
      </tr>


      </tbody>

    </table>
  </div>
</template>

<script>
export default {
  name: 'GradeTable',
  data() {
    return {
      term_map: ["大一上", "大一下", "大二上", "大二下", "大三上", "大三下", "大四上", "大四下"],
    };
  },
  props: {
    grades: {
      type: Array,
      required: true,
    },
  },
  methods: {},

};
</script>

<style scoped>
.container {
  max-width: 800px;
  margin: auto;
}



table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

th, td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: center;
}

th {
  background-color: #f2f2f2;
}

tr:nth-child(even) {
  background-color: #f9f9f9;
}

tr:hover {
  background-color: #ddd;
}

/* 响应式设计 */
@media screen and (max-width: 600px) {
  table, thead, tbody, th, td, tr {
    display: block;
  }

  #table_header {
    display: none;
  }

  th {
    display: none;
  }

  tr {
    margin-bottom: 10px;
    border: 1px solid #75c3f4;
    border-radius: 5px;
    padding: 10px;
  }

  td {
    display: flex;
    justify-content: space-between;
    padding: 5px;
    text-align: left;
    border: none;
    border-bottom: 1px solid #ddd;
  }

  td:last-child {
    border-bottom: 0;
  }

  td:before {
    content: attr(data-label);
    font-weight: bold;
    flex-basis: 50%;
  }
}
</style>
